package org.openkanban.client.ui.presenter;

import org.openkanban.client.ui.board.BoardView;
import org.openkanban.client.ui.footer.Footer;
import org.openkanban.client.util.RootPanel;
import org.openkanban.shared.dto.BoardDto;

import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;

/**
 * Callback that handles create Board Response
 */
public class CreateBoardRequestCallback implements RequestCallback {

    @Override
    public void onResponseReceived(Request request, Response response) {
	BoardView boardView = RootPanel.main.getBoard();
	Footer footer = RootPanel.main.getFooter();

	if (response.getStatusCode() == 200) {
	    BoardDto boardDto = new BoardDto(response.getText());
	    boardView.getWhiteBoardView().setBoardDto(boardDto);
	    boardView.getWhiteBoardView().subscribe();

	    boardView.publish();

	    RootPanel.activateBoardEditMode(false);

	    boardView.showNewActivityButton();
	    boardView.enableNewActivityButton();

	    footer.showBoardContactTileGrid();
	}
    }

    @Override
    public void onError(Request request, Throwable exception) {
	GWT.log(exception.getMessage());
    }

}
